package top.maof.book.spider.develop.contents.booktxt;

import lombok.Data;
import top.maof.book.model.Book;
import top.maof.book.model.Contents;
import top.maof.book.spider.develop.Split;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.model.AfterExtractor;
import us.codecraft.webmagic.model.annotation.ExtractBy;
import us.codecraft.webmagic.model.annotation.HelpUrl;
import us.codecraft.webmagic.model.annotation.TargetUrl;

import java.util.Date;

/**
 * 顶点小说
 * 站点有防盗链,抓不了
 */
@Deprecated
@Data
@TargetUrl("https://www.booktxt.com/\\d\\w+")
@HelpUrl("https://www.booktxt.com/\\D\\w+")
public class BookTxt implements AfterExtractor, Split {
    public static final String CHARSET = "gbk";

    @ExtractBy(value = "div#maininfo div#info h1", type = ExtractBy.Type.Css, notNull = true)
    private String name;

    @ExtractBy(value = "div#maininfo div#info p:first-child", type = ExtractBy.Type.Css, notNull = true)
    private String author;

    @ExtractBy(value = "div#sidebar div#fmimg img", type = ExtractBy.Type.Css)
    private String img;

    @ExtractBy(value = "div.box_con div.con_top a:nth-child(2) text", type = ExtractBy.Type.Css)
    private String classify;

    private Date updateDate;

    private String synopsis;

    private String url;

    private String content;

    @Override
    public Book getBook() {
        Book book = new Book();
        book.setAuthor(this.author);
        book.setImg(this.img);
        book.setName(this.name);
        book.setClassify(this.classify);
        book.setSynopsis(this.synopsis);
        return book;
    }

    @Override
    public Contents getContents() {
        Contents contents = new Contents();
        contents.setUrl(this.url);
        return contents;
    }


    @Override
    public void afterProcess(Page page) {
        this.setUrl(page.getRequest().getUrl());
    }


}
